const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')

// 练习 1
let maybe = Maybe.of([5, 6, 1])
let ex1 = maybe.map(function(v) {
  let values = fp.map(fp.add(1),v)
  return values
})
console.log(ex1)

// 练习 2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = fp.map(fp.first, xs)
console.log(ex2)

// 练习 3
let safeProp = fp.curry(function(x,o){
  return Maybe.of(o[x])
})
let user = {id: 2, name: 'albert'}
let ex3 = fp.flowRight(fp.map(fp.first), safeProp('name'))
console.log(ex3(user))

// 练习 4
let ex4 = n => {
  let v = Maybe.of(n)
  return fp.map(parseInt,v)
}
console.log(ex4(32))